package com.neuedu.security.service;

import com.neuedu.security.mapper.CategoryMapper;
import com.neuedu.security.model.Category;
import com.neuedu.security.model.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class CategoryService {

    @Autowired
    CategoryMapper categoryMapper;


    public RespBean addCategory(Category category) {
        category.setCreatetime(new Date());
        int num = categoryMapper.addCategory(category);
        if (num == 0) {
            return RespBean.fail(500, "新增栏目失败！");
        } else {
            return RespBean.success(200, "新增栏目成功！");
        }
    }

    public RespBean delCategory(int id) {
        int num = categoryMapper.delCategory(id);
        if (num == 0) {
            return RespBean.fail(500, "删除栏目失败！");
        } else {
            return RespBean.success(200, "删除栏目成功！");
        }
    }

    public RespBean delCategories(int[] ids) {
        int num = categoryMapper.delCategories(ids);
        if (num == 0) {
            return RespBean.fail(500, "批量删除栏目失败！");
        } else {
            return RespBean.success(200, "批量删除栏目成功！");
        }
    }

    public RespBean updateCategory(Category category) {
        int num = categoryMapper.updateCategory(category);
        if (num == 0) {
            return RespBean.fail(500, "更新栏目失败！");
        } else {
            return RespBean.success(200, "更新栏目成功！");
        }
    }

    public List<Category> getCategory(String keyWords) {
        return categoryMapper.getCategory(keyWords);
    }
}
